<?php
# Functions Version 0.1

function content($page){
	if ($page == ''){ $page = 'home'; }
	$sql = "SELECT "."content, pagetitle, tags, url, level"." FROM "."content "." WHERE "."(url = '".$page."')"; 
	$result = mysql_query ($sql);
	$db = mysql_fetch_array ($result);
	if ($db['level'] == '0'){
		return $db;
	}
	else {
		if ($_COOKIE['xesus_user_level'] <= $db['level']){
			$db['content'] = "Keine Rechte";
			$db['pagetitle'] = "Keine Rechte";
			$db['tags'] = "Keine Rechte";
			return $db;
		}
		return $db;
	}
}

function login($user, $pass){
	$sql = "SELECT "."id, username, password, name, email, level"." FROM "."users "." WHERE "."(username like '".$user."') AND "."(password = '".$pass."')";
	$result = mysql_query ($sql);

	if (mysql_num_rows ($result) > 0)  
	{  
  		// Benutzerdaten in ein Array auslesen.  
  		$data = mysql_fetch_array ($result);  

  		// Set Cookies
  		$vartime = time() + (60*60*24*7); //(60*60*24*7)
  		setcookie("xesus_user_id", $data['id'], $vartime);
  		setcookie("xesus_user_level", $data['level'], $vartime);
  		setcookie("xesus_user_username", $data['username'], $vartime);
  		setcookie("xesus_user_email", $data['email'], $vartime);
  		setcookie("xesus_user_name", $data['nachname'], $vartime);

		$login = 'true';
  		return $login; 
	}
	
	else  
	{
		$login = 'false';
  		return $login;
	}
}
?>